<?php

/**
 * Cloud Simple Objects
 * http://cloud.serverboy.net/
 *
 * PHP version 5
 *
 * Copyright 2009 Matt Basta
 * 
 * @author     author matt@serverboy.net
 * @link       http://serverboy.net/
*/

// Simple comparison (two terms)

class comparison extends cloud_base {
	public function __construct($obj1, $comparison, $obj2) {
		
		// Make sure the comparison is a valid comparison operator
		$supported_comparisons = array(
			'=', // May be interpreted as ==
			'>',
			'<',
			'>=',
			'<=',
			'!=',
			'LIKE',
			'NOT LIKE',
			'STARTS WITH',
			'IN', // < May need to be virtualized in
			'IS NULL',
			'IS NOT NULL'
			// To be virtualized or optimized in:
			// - BETWEEN (SimpleDB)
			// - IN (SimpleDB, [Array-based values])
		);
		
		$comparison = strtoupper($comparison);
		if(!in_array($comparison, $supported_comparisons))
			cloud_logging::unsafe_query(
				'Comparisons',
				"Comparison Operator ($comparison)",
				array(
					'This is not a globally supported db comparison operator.',
					'> Possible disintegration of intended data set',
					'> Possible corruption of data',
					'> Possible incorrect reporting of data'
				)
			);
		
		
		// Store the objects securely
		self::readOnly('object_1', $obj1);
		self::readOnly('comparison', $comparison);
		self::readOnly('object_2', $obj2);
	}
	
	public function getObject1() {return self::readOnly('object_1');}
	public function getObject2() {return self::readOnly('object_2');}
	public function getOperation() {return self::readOnly('comparison');}
}



class logicCombinator extends cloud_base {
	
	public function __construct($terms, $logic) {
		// Make sure the comparison is a valid comparison operator
		$supported_logic = array(
			'AND',
			'OR',
			'NOT'
		);
		
		if(!is_array($terms) || count($terms) < 1)
			cloud_logging::unsafe_query(
				'Comparisons',
				'Comparison Logic',
				array(
					'An empty logic combinator was supplied.',
					'> Your logic may be flawed',
					'> Database errors may occur',
				)
			);
		
		$logic = strtoupper($logic);
		if(!in_array($logic, $supported_logic))
			cloud_logging::unsafe_query(
				'Comparisons',
				"Comparison Logic ($comparison)",
				array(
					'This is not a globally supported boolean logic combinator.',
					'> Possible disintegration of intended data set',
					'> Possible corruption of data',
					'> Possible incorrect reporting of data'
				)
			);
		
		self::readOnly('logic', $logic);
		self::readOnly('terms', $terms);
	}
	
	public static function getLogic() {return self::readOnly('logic');}
	public static function getTerms() {return self::readOnly('terms');}
	
}

// Order

class listOrder extends cloud_base {
	
	public function __construct($variable, $order) {
		
		$supported_orders = array(
			'DESC',
			'ASC'
		);
		
		$order = strtoupper($order);
		if(!in_array($order, $supported_orders))
			cloud_logging::unsafe_query(
				'Order',
				"Directionality ($order)",
				array(
					'This is not a globally supported directionality for order.',
					'> Possible return of unnecessary information',
					'> Possible disintegration of data output'
				)
			);
		
		self::readOnly('variable', $variable);
		self::readOnly('order', $order);
	}
	
	public function getVariable() {return secure::readOnly('variable');}
	public function getOrder() {return secure::readOnly('order');}
	
}

// Simple tokens (i.e.: table names, 

class simpleToken extends cloud_base {
	
	public function __construct($token) {
		secure::readOnly('token', $token);
	}
	
	public function getToken() {return secure::readOnly('token');}
	
}

